package com.jixi.controller;

import com.jixi.common.result.PageResultByReturnOrderDetail;
import com.jixi.common.result.Result;
import com.jixi.pojo.dto.RefundStatusDto;
import com.jixi.pojo.dto.ReturnDownloadDto;
import com.jixi.pojo.entity.ReturnOrderDetail;
import com.jixi.service.ReturnOrderDetailService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/education")
public class ReturnOrderDetailController {
	
	@Autowired
	private ReturnOrderDetailService returnOrderDetailService;
	
	/**
	 * 退餐订单列表
	 *
	 * @param pageNum 页码
	 * @param pageSize 每页数量
	 * @param returnNumber 退餐订单编号
	 * @param companyId    餐饮公司id
	 * @param schoolId     学校id
	 * @param bankCardHolder 接收退款的银行卡持卡人姓名
	 * @param cardNumber     接收退款的银行卡号
	 * @param returnStatus 退餐订单状态
	 * @param timeValue    时间（月）
	 * @return 退餐订单列表
	 */
	@GetMapping("/return/list")
	public Result<PageResultByReturnOrderDetail> returnList(
			Integer pageNum,
			Integer pageSize,
			String returnNumber,
			Long companyId,
			Long schoolId,
			String bankCardHolder,
			String cardNumber,
			Integer returnStatus,
			String timeValue
	) {
		return returnOrderDetailService.returnOrderPage(pageNum,pageSize,returnNumber,companyId,schoolId,bankCardHolder,cardNumber,returnStatus,timeValue);
	}
	
	/**
	 * 退餐订单详情
	 *
	 * @param returnDetailId 退餐订单id
	 * @return 退餐订单详情
	 */
	@GetMapping("/return/info")
	public Result<ReturnOrderDetail> getInfo(Long returnDetailId) {
		ReturnOrderDetail returnOrderDetail = returnOrderDetailService.getReturnOrderInfoById(returnDetailId);
		return Result.success(returnOrderDetail);
	}
	
	/**
	 * 2导出各公司各学校按月统计的退餐统计excel
	 *
	 * */
	@GetMapping("/return/month/list/download")
	@Operation(summary = "各公司各学校按月统计的退餐统计")
	public void downloadMonthReturnOrder(HttpServletResponse response, ReturnDownloadDto returnDownloadDto) throws IOException {
		returnOrderDetailService.downloadReturnOrder(response,returnDownloadDto);
	}
	
	/**
	 * 单选/批量修改退餐订单退款状态
	 *
	 * @param refundStatusDto 参数：退餐订单id数组、退款状态
	 * @return 操作结果
	 */
	@PutMapping("/return/changeRefundStatus")
	public Result changeRefundStatus(RefundStatusDto refundStatusDto) {
		return returnOrderDetailService.updateReturnOrderRefundStatus(refundStatusDto.getReturnDetailIds(), refundStatusDto.getRefundStatus());
	}
	
}
